package util;

import java.awt.Dimension;
import java.awt.Font;

import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

/**
 * Debugging Hilfsklasse
 * @author Sebastian Althof <get@itnuts.de>
 * @version 1.0.0
 */
public class Debug {
	/**
	 * Debug window functionality added by Jolle
	 */
	static JTextArea textArea = null;
	public static JFrame frame = null;
	/**
	 * Print methode
	 * @param msg
	 */
	public static void print(String msg) {
		if(Config.DEBUG) {
			System.out.println(msg);
			if (frame != null) {
				textArea.append(msg + "\n");
				int last = textArea.getText().length();
				textArea.select(last, last);
			}
		}
	}
	/**
	 * Show this as debug window.
	 * @author Jolle
	 */
	public static void show() {
		textArea = new JTextArea();
		textArea.setFont(new Font("Courier New", Font.PLAIN, 12));
		JScrollPane scrollPane = new JScrollPane(textArea);
		frame = new JFrame("Debug window");
		frame.add(scrollPane);
		frame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
		frame.setSize(new Dimension(200, 300));
		frame.setVisible(true);
	}
}
